const connection = require("../app/database");

class PermissionService {
  async checkMoment(momentId, userId) {
    const statement = "select * from moment where id = ? and user_id = ?;";

    const [result] = await connection.execute(statement, [momentId, userId]);

    return !!result.length;
  }

  async checkResouce(resourceName, resourceId, userId) {
    const statement = `select * from ${resourceName} where id = ? and user_id = ?;`;
    const [result] = await connection.execute(statement, [resourceId, userId]);

    return !!result.length;
  }
}

module.exports = new PermissionService();
